package me.xuym.crawler.simpleextension.entity;

import me.xuym.crawler.simpleextension.dispatcher.SimpleDebugDispatcherInput;
import me.xuym.crawler.simpleextension.dispatcher.SimpleEmailDispatcherInput;
import me.xuym.crawler.simpleextension.filter.SimpleBlackFilterInput;
import me.xuym.crawler.simpleextension.filter.SimpleCachedFilterInput;
import me.xuym.crawler.simpleextension.filter.SimpleWhiteFilterInput;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

/**
 * Created by broche on 09/09/2017.
 */
public class SimpleLinkResult implements SimpleDebugDispatcherInput, SimpleBlackFilterInput, SimpleWhiteFilterInput, SimpleCachedFilterInput, SimpleEmailDispatcherInput {
    private String url;
    private String content;

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String simpleDebugDispatcherContent() {
        return String.format("url: %s\ncontent: %s\n\n", url, content);
    }

    @Override
    public List<String> simpleBlackFilterFields() {
        List<String> fields = new ArrayList<>();
        fields.add(getUrl());
        fields.add(getContent());
        return fields;
    }

    @Override
    public List<String> simpleWhiteFilterFields() {
        List<String> fields = new ArrayList<>();
        fields.add(getUrl());
        fields.add(getContent());
        return fields;
    }

    @Override
    public Map<String, String> simpleCachedFilterCheckFields() {
        Map<String, String> fields = new Hashtable<>();
        fields.put("url", getUrl());
        fields.put("content", getContent());
        return fields;
    }

    @Override
    public Map<String, String> simpleCachedFilterSaveFields() {
        Map<String, String> fields = new Hashtable<>();
        fields.put("url", getUrl());
        fields.put("content", getContent());
        return fields;
    }


    @Override
    public String simpleEmailDispatcherContent() {
        return String.format("<a href=\"%s\">%s</a>", getUrl(), getContent());
    }
}
